package com.zyp.springdemo.web;

import com.zyp.springdemo.entity.Area;
import com.zyp.springdemo.entity.ResultModel;
import com.zyp.springdemo.entity.ResultTools;
import com.zyp.springdemo.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 *  http://localhost:8083/superAdmin/getAreaList
 *  http://localhost:8083/superAdmin/addArea
 *  http://localhost:8083/superAdmin/getAreaById?areaId=1
 *
 */
@RestController
@RequestMapping("/superAdmin")
//@Controller
//@ResponseBody
//@RestController注解相当于@ResponseBody ＋ @Controller合在一起的作用
public class AreaController {
    @Autowired
    private AreaService areaService;

    @RequestMapping(value = "/getAreaList", method = RequestMethod.GET)
    private ResultModel getAreaList(){
        Map<String,Object> modelMap = new HashMap<>();
        List<Area> areaList = areaService.getAreaList();
        modelMap.put("area_list",areaList);
        return ResultTools.resultSucess(modelMap);
    }

    @RequestMapping(value = "/getAreaById", method = RequestMethod.GET)
    private ResultModel getAreaList(@RequestParam(value = "areaId") Integer areaId){
        Map<String,Object> modelMap = new HashMap<>();
        Area area = areaService.getAreaById(areaId);
        modelMap.put("area",area);
        return ResultTools.resultSucess(modelMap);
    }

    @RequestMapping(value = "/addArea", method = RequestMethod.POST)
    private ResultModel addArea(@RequestBody Area area){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("success",areaService.addArea(area));
        return ResultTools.resultSucess(modelMap);
    }

    @RequestMapping(value = "/modifyAreaById", method = RequestMethod.POST)
    private ResultModel modifyArea(@RequestBody Area area){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("success",areaService.modifyArea(area));
        return ResultTools.resultSucess(modelMap);
    }


    @RequestMapping(value = "/deleteAreaById", method = RequestMethod.GET)
    private ResultModel deleteArea(Integer areaId){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("success",areaService.deleteArea(areaId));
        return ResultTools.resultSucess(modelMap);
    }


}
